﻿using Abp.Application.Services;
using Abp.Domain.Repositories;
using Batman.Core;
using Batman.Jianbei.Forum.Areas.Forum.Responses;
using Batman.Jianbei.Forum.Core.Domains.Posts;
using Batman.Jianbei.Forum.Core.Domains.Socials;
using Batman.Jianbei.Forum.Core.Domains.Users;
using Batman.Jianbei.Forum.Core.Enums;
using System;
using System.Linq;

namespace Batman.Jianbei.Forum.Services.Forum
{
    public class SummaryService : ApplicationService
    {
        public IRepository<WeixinUser, String> WxUserRepo { get; set; }

        public IRepository<Post, string> PostRepo { get; set; }

        public IRepository<Follow, string> FollowRepo { get; set; }

        /// <summary>
        /// 论坛首页/用户主页 汇总信息
        /// </summary>
        public SummaryInfo GetSummaryInfo(string wxUId)
        {

            var wxUser = WxUserRepo.GetQuery().FirstOrDefault(t => t.Id == wxUId);


            SummaryInfo result = new SummaryInfo
            {
                Avatar = wxUser?.Avatar,
                Nickname = wxUser?.Nickname,
                WxUId = wxUser?.Id
            };


            result.PostCount = PostRepo.GetQuery().Count(t => t.Status == PostStatus.published && t.WxUserId == wxUId);

            result.FollowingCount = FollowRepo.GetQuery().Count(t => t.FollowBy == wxUId); // 统计我的关注
            result.FollowerCount = FollowRepo.GetQuery().Count(t => t.WxUserId == wxUId); // 统计关注我的人

            return result;
        }
    }
}
